<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>分配角色</title>
	<base href="<%=basePath%>">
	<script type="text/javascript" src="res/layui/jquery-1.9.1.min.js"></script>
	<script src="res/layui/layui.js"></script>
      <link rel="stylesheet" href="res/layui/css/layui.css"></head>
</head>
<body>
<form class="layui-form" action="" style="margin:20px;" id="formstaffrole">
	<input type="hidden" value="" id="staffId" name="staffId"/>
	<div class="layui-inline">
      <label class="layui-form-label">分配角色</label>
      <div class="layui-input-inline">
        <select name="roleId" id="roleId" lay-verify="required" lay-search="" class="optsave">
          
        </select>
      </div>
    </div>
    <input type="button" class="layui-btn" lay-submit="" lay-filter="demo1" value="立即提交" onclick="btntj()">
  </div>
  </form>
<script>
	var url = "<%=basePath%>/role/showroleAll.action";
	$.ajax({
		  type:'post',
		  url:url,
		  dataTye:'json',
		  success:function(info){
			 var htm = "";
			 for(var i=0;i<info.length;i++){
				 htm+=" <option value='"+info[i].roleId+"'>"+info[i].roleName+"</option>";
			 }
			 $(".optsave").html(" <option value=''>请选择角色</option>"+htm);
		  }
	});
  $(function(){
	  
	  
	  var id = GetQueryString("staffId");
	  $("#staffId").val(id);
  });
  
	layui.use(['form'], function(){
	  var form = layui.form;
	});
	function btntj(){
		var url = "<%=basePath%>/personelrole/savepersonelrole.action";
		
		$.ajax({
			type:'post',
			url:url,
			data:$("#formstaffrole").serialize(),
			dataTye:'json',
			success:function(info){
				if(info.state=="1"){
        			layer.msg(info.mes);
        			 var index = parent.layer.getFrameIndex(window.name);  
     			    parent.layer.close(index);
     			    parent.layer.msg("保存成功!");
        		}else{
        			layer.msg(info.mes);
        		}
			   
			   	
			}
		});
	}
	
	
	function GetQueryString(id){
	     var reg = new RegExp("(^|&)"+ id +"=([^&]*)(&|$)");
	     var r = window.location.search.substr(1).match(reg);
	     if(r!=null)return  unescape(r[2]); return null;
	}
</script>
  
</body>
</html>